#ifndef DATA_PROCESSOR_H
#define DATA_PROCESSOR_H

#include <deque>
#include <mutex>
#include <memory>
#include <iostream>
#include "data_handler.h"
#include "msg_topic.h"
#include "global_status_manager.h"
#include "config.h"
#include "data_fusion.h"
using namespace std;
// 数据处理器类

enum class SENSOR {
    ALL = 0,
    AI = 1,
    LIDAR = 2,
    INVALID = -1
};
class DataProcessor : public DataHandler {
public:
    DataProcessor();  // 显式声明默认构造函数

    // 重写 handleData 方法
    // void handleLidarData(const msg::ObstacleData::SharedPtr& data) override;
    // void handleAIData(const msg::AiMetadata::SharedPtr& data) override;
    void handleData(const std::shared_ptr<void>& data, DataType type) override;
    void startProcessingThread();
    void processMessages();
    void Init();




private:
    // 处理并存储数据
    void SubLidarObstacleData(const msg::ObstacleData::SharedPtr& data);

    void SubAiMetadata(const msg::AiMetadata::SharedPtr& data);
    void processAppData(const msg::AppCamdar::SharedPtr& data);


    bool findClosestLidarData(msg::AiMetadata& closest_ai_data, msg::ObstacleData& closest_lidar_data);

    bool matchingSteps(int type, int& status, msg::ObstacleData& cur_lidar_data, msg::AiMetadata& cur_ai_data);
    void multiSenosrs();
    void LidarSensor();
    // void lidarSensors();

    // StateConfigManager* stateManager_; // 指针类型

    std::deque<msg::AiMetadata::SharedPtr> ai_data_deque_;
    std::deque<msg::ObstacleData::SharedPtr> lidar_data_deque_;
    std::mutex ai_deque_mutex_;
    std::mutex lidar_deque_mutex_;
    std::condition_variable data_cond_;
    std::thread processing_thread_;

    bool start_matching_ = false;
    bool bSwitch = false;
    // bool bLogic = false;
    int last_data_type_ = 0;
    bool buse_frames = true;

    // int64_t TIME_DIFF = 499;
    // int64_t LIDAR_INTERVAL = 1000;
    // int64_t AI_INTERVAL = 1660;

    Config cfg_; 
    std::shared_ptr<DataFusion> data_fusion_; // DataFusion 的智能指针

};

#endif // DATA_PROCESSOR_H
